/* $Id:has_special.cc $ */
/*
   Copyright (C) 2007 by Jurjen Stellingwerff <jurjen@stwerff.xs4all.nl>
   Part of the Moros Project http://moros.sourceforge.net/

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License version 3.
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY.

   See the COPYING file for more details.
*/

#define DEBUG_ROUTINE "has_special"

#include <sstream>
#include <fstream>
#include "../general/util.h"
#include "../general/log.h"
#include "../general/channel.h"
#include "has_special.h"
#include "special.h"
#include "../general/general.h"

has_special::has_special() {
    special=0;
}

// Field : special

class special& has_special::getSpecial() const { if (special==0) throw nullpointer(); return *special; }
void has_special::setSpecial(class special &v) { special=&v; }

void has_special::save(class channel &ch) {
    ch.write("has_special", "");
    ch.write("s", getSpecial().getName());
}

void has_special::load(class channel &ch) {
    if (ch.key=="s" || ch.key=="special") {
        if (!special_repo.isSpecial(ch.value)) {
            dbg_state("link unknown special %s", ch.value.c_str());
            class special rec;
            rec.setName(ch.value);
            special_repo.setSpecial(rec);
        }
        setSpecial(special_repo.getSpecial(ch.value));
        ch.next();
    }
}

void has_special::xml(ofstream &f, int l, int r) {
    f << ncpy(l, "  ") << "<has_special>" << endl;
    if (r<2) try {
        getSpecial().xml(f,l+1,r+1);
    } catch (nullpointer n) {}
    f << ncpy(l, "  ") << "</has_special>" << endl;
}
